﻿<template>
  <div class="container" style="width:99%;margin-top:-25px;">
    <!-- 查询条件 -->
    <div class="query-box">
      <el-form :model="queryBox" status-icon ref="queryBox">
        <el-row>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户类型</div>
              <el-select clearable filterable v-model="queryBox.type" filterable>
                <el-option
                  v-for="item in student_type_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户来源</div>
              <el-select filterable clearable v-model="queryBox.dataFrom" filterable>
                <el-option
                  v-for="item in student_data_from_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </div>
          </el-col>

          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户进展</div>
              <el-form-item @change="student_progress_change">
                <el-select clearable filterable v-model="queryBox.progress" placeholder="请选择">
                  <el-option
                    v-for="item in student_progress_options"
                    :key="item.key"
                    :label="item.value"
                    :value="item.key"
                  >{{item.value}}</el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="4">
            <el-form-item label prop="code">
              <el-input clearable v-model="queryBox.code" placeholder="客户编号">
                <template slot="prepend">客户编号</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label prop="name">
              <el-input clearable v-model="queryBox.name" placeholder="学校名称">
                <template slot="prepend">学校名称</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <el-form-item label prop="contact">
              <el-input clearable v-model="queryBox.contact" placeholder="请输入联系人">
                <template slot="prepend">联系人</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label prop="phone">
              <el-input clearable v-model="queryBox.phone" placeholder="请输入联系电话">
                <template slot="prepend">联系电话</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <el-form-item label prop="isTodayTracking">
                <div class="depart-box">
                  <div class="slect-title">今日应跟进</div>
                  <el-select clearable v-model="queryBox.isTodayTracking" filterable>
                    <el-option
                      v-for="item in isTodayTracking_options"
                      :key="item.lable"
                      :label="item.value"
                      :value="item.label"
                    ></el-option>
                  </el-select>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="9">
            <el-row class="area">
              <el-col :span="6">
                <span class="city-title">所在地区：</span>
              </el-col>
              <el-col :span="17" style="margin-left:-1px">
                <el-form-item label prop="area">
                  <el-cascader
                    clearable
                    size="large"
                    :options="options"
                    v-model="selectedOptions"
                  ></el-cascader>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7">
            <div class="depart-box">
              <div class="slect-title">创建时间</div>
              <el-date-picker
                v-model="createDateArr"
                type="daterange"
                :start-placeholder="'开始时间'"
                :end-placeholder="'结束时间'"
                range-separator="至"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
          <el-col :span="7">
            <div class="depart-box">
              <div class="slect-title">最新跟进时间</div>
              <el-date-picker
                clearable
                v-model="trackingDateArr"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="depart-box">
              <div class="slect-title">学段</div>
              <el-select clearable multiple v-model="schoolSectionArr" filterable>
                <el-option
                  v-for="item in student_level_cache_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div class="from-btns">
        <kt-button
          :label="$t('action.reset')"
          perms="true"
          type="primary"
          @click="reset('queryBox')"
        />
        <kt-button
          :label="$t('action.search')"
          perms="true"
          type="primary"
          @click="get_subcentersearch"
        />
      </div>
    </div>
    <!-- 批量删除按钮 -->
    <div class="add-btns fl">
      <kt-button
        :label="$t('action.batchDelete')"
        perms="mycustomer:school:delete"
        :size="size"
        type="danger"
        @click="handleBatchDelete"
        :disabled="this.selections.length===0"
        style="float:left;"
      />
    </div>
    <div class="fr">
      <kt-button
        :label="$t('action.download-tmpl')"
        type="primary"
        perms="mycustomer:school:download"
        @click="downloadTmpl"
      ></kt-button>
      <kt-button
        :label="$t('action.batchimport')"
        type="primary"
        perms="mycustomer:school:batchimport"
        @click="customerManagerImport"
      ></kt-button>
      <kt-button
        :label="$t('action.add-user')"
        type="primary"
        perms="mycustomer:school:add"
        @click="handleNewADD"
      ></kt-button>
    </div>
    <!--表格内容栏-->
    <div class="btn">
      <Crm-table
        @selectionChange="selectionChange"
        class="table-width"
        Mycustomerschool
        width="400"
        permsEdit="mycustomer:school:edit"
        permsSee="mycustomer:school:see"
        permsFollow="mycustomer:school:follow"
        :data="pageResult"
        :columns="columns"
        :loading='loading'
        @findPage="findPage"
        @changeSwitch="changeSwitch"
        @handleEdit="handleEdit"
        @handleSee="handleSee"
        @handleFollow="handleFollow"
      ></Crm-table>
    </div>
    <!--批量分配-->
    <!--导入-->
    <el-dialog :title="'批量导入'" width="30%" :visible.sync="uploadOem" :close-on-click-modal="false">
      <el-form :model="form">
        <el-form-item>
          <el-upload
            ref="uploadExcel"
            :action="uploadUrl"
            :limit="limitNum"
            :auto-upload="false"
            accept=".xls"
            :before-upload="beforeUploadFile"
            :on-change="fileChange"
            :on-exceed="exceedFile"
            :on-success="handleSuccess"
            :on-error="handleError"
            :file-list="fileList"
            :on-remove="handleRemove"
          >
            <el-button size="small" plain>选择文件上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传xls(Excel97-2004)文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="uploadOem = false">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" type="primary" @click.native="uploadFile">{{$t('立即上传')}}</el-button>
      </div>
    </el-dialog>

    <!-- 跟进 -->
    <el-dialog
      :title="saveData.name"
      width="70%"
      :visible.sync="addFollow"
      :close-on-click-modal="false"
    >
      <div class="second-contain-box ma school-pop">
        <el-row>
          <el-col :span="12">
            <el-col :span="12">
              <i style="margin-top:0">跟进次数：{{saveData.trackingNum}}</i>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="8">
              <i style="margin-top:0">跟进时间：</i>
            </el-col>
            <el-col :span="16">
              <span>{{saveData.trackingDate}}</span>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>联系人：</i>
            </el-col>
            <el-col :span="16">
              <el-input placeholder="请输入内容" v-model="saveData.contactTrack"></el-input>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>沟通形式：</i>
            </el-col>
            <el-col :span="18">
              <el-select style="width:100%" v-model="saveData.communicationType" placeholder="请选择">
                <el-option
                  v-for="item in student_communication_type"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>客户类型：</i>
            </el-col>
            <el-col :span="16">
              <el-select
                style="width:100%"
                :disabled="typeDisabled"
                v-model="saveData.type"
                placeholder="请选择"

              >
                <el-option
                  v-for="item in student_type_options"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>客户进展：</i>
            </el-col>
            <el-col :span="18">
              <el-select
                style="width:100%"
                :disabled="selectDisabled"
                v-model="saveData.progress"
                placeholder="请选择"
                
              >
                <el-option
                  v-for="item in student_progress_options"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i>沟通内容：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="saveData.communicationContent"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <i style="margin-top:5%">跟进人：{{trackingPeople}}</i>
          </el-col>
          <el-col :span="12">
            <el-col :span="8">
              <i>下次跟进日期：</i>
            </el-col>
            <el-col :span="16">
              <el-date-picker
                style="width:100%"
                v-model="saveData.nextTrackingDate"
                type="datetime"
                placeholder="选择日期时间"
                :default-time="mytime"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-col>
          </el-col>
        </el-row>
      </div>
      <kt-button
        class="stu-btn"
        :label="$t('action.save')"
        perms="true"
        size="medium"
        type="primary"
        @click="handleSave()"
      />
      <p class="tracking-tit">跟进情况</p>
      <Crm-table   
        :showBatchDelete="showBatchDelete" 
        class="tracking-table"
        :data="stuqueryTrackingData" 
        :columns="columns2"
        @findPage2='findPage2'
        :loading="loading">
    </Crm-table >
    </el-dialog>
  </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import StTable from "@/views/Core/StTable";
import CrmTable from "@/views/Core/CrmTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { CodeToText } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import { regionDataPlus } from "element-china-area-data";
import axios from "axios";
import Cookies from "js-cookie";
export default {
  name: "School",
  components: {
    PopupTreeInput,
    CrmTable,
    KtButton,
    CrmSwitch
  },
  data() {
    return {
      isShowFlag: 0, //0:初始化部门、人员不显示  1:部门显示 2：人员显示
      showBatchDelete:false,
      mytime:'',
      size: "mini",
      selectDisabled: false, //跟进弹窗客户进展状态
      typeDisabled: false,
      schoolSectionArr: [], //学段数组
      filters: {
        name: ""
      },
      uploadOem: false, //文件上传
      limitNum: 1, //上传最大个数
      form: {
        file: ""
      },
      isTodayTracking: "",
      fileList: [],
      uploadUrl: baseUrl + "/file/upload", //文件上传地址
      downloadTmplUrl: baseUrl + "/template/schoolImportTemplate.xlsx", //模板下载地址
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
       // 客户跟进数据
      stuqueryTrackingData:{
          content:[]
      },
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_type_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_progress_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_data_from_type_options: [
        {
          label: " ",
          key: " "
        }
      ],

      isTodayTracking_options: [
        {
          value: "是",
          label: "1"
        }
      ],

      student_level_cache_options: [
        {
          key: " ",
          value: " "
        }
      ],
      createDateArr: [], // 创建时间数组
      trackingDateArr: [], //跟进时间数组
      student_communication_type: [],
      queryBox: {
        type: "",
        dataFrom: "",
        progress: "",
        code: "",
        name: "",
        schoolSection: "",
        belongToId: "",
        thirdPatry: "",
        isLock: "",
        createDateStart: "", //创建开始时间
        createDateEnd: "", //创建结束时间
        trackingDateStart: "", //最新跟进开始时间
        trackingDateEnd: "", //最新跟进结束时间
        orderName: "",
        orderType: "",
        id: ""
      },
      columns: [
        { type: "index", label: "序号", minWidth: 50 },
        { prop: "name", label: "学校名称", minWidth: 100 },
        { prop: "xueDuan", label: "学段", minWidth: 100 },
        { prop: "laiyuan", label: "客户来源", minWidth: 80 },
        // { prop: "type", label: "客户类型", minWidth: 120 },
        { prop: "jinzhan", label: "客户进展", minWidth: 80 },
        { prop: "contact", label: "联系人", minWidth: 100 },
        { prop: "phone", label: "联系电话", minWidth: 100 },
        { prop: "diqu", label: "地区", minWidth: 190 },
        { prop: "createDate", sortable:'true', label: "创建时间", minWidth: 140 },
        { prop: "trackingDate", sortable:'true', label: "最新跟进时间", minWidth: 140 },
        { prop: "code", label: "客户编号", minWidth: 150 },
      ],
      columns2: [
        { type: "index", label: "序号", minWidth: 10 },
        { prop: "trackingDate", label: "跟进时间", minWidth: 100 },
        { prop: "contactTrack", label: "联系人", minWidth: 50 },
        { prop: "typeTrack", label: "客户类型", minWidth: 80 },
        { prop: "progressTrack", label: "客户进展", minWidth: 50 },
        { prop: "communicationType", label: "沟通形式", minWidth: 50 },
        { prop: "communicationContent", label: "沟通内容", minWidth: 120 },
        { prop: "nextTrackingDateDetail", label: "下次跟进时间", minWidth: 100 }
      ],
      pageResult: {
        content: []
      },
      operation: false, // true:新增, false:编辑
      batchdistribution: false, //显示批量分配弹窗
      selectionsLength: "",
      selections: [], //选中列表集合
      ids: [], //分配ID集合
      deptData: [], //部门树
      deptTree: {
        label: "deptName",
        children: "children"
      },
      addFollow: false, //显示跟进窗口
      deptinputValue: "",
      // 划分方式
      deptmodeoptions: [
        {
          label: "分配至部门",
          value: "11"
        },
        {
          label: "分配至个人",
          value: "9"
        }
      ],

      deptuseroption: [], //部门用户
      addstuformData: {},
      deptmodeoptionsValue: "",

      AllotData: {
        assignType: 2,
        schoolIds: "",
        thirdLevelDepartment: "",
        belongToId: "",
        belong_to_type: ""
      },
      // 地区
      options: regionDataPlus,
      selectedOptions: [],
      saveData: {
       type: "",
        dataFrom: "",
        progress: "",
        code: "",
        name: "",
        schoolSection: "",
        belongToId: "",
        thirdPatry: "",
        isLock: "",
        createDateStart: "", //创建开始时间
        createDateEnd: "", //创建结束时间
        trackingDateStart: "", //最新跟进开始时间
        trackingDateEnd: "", //最新跟进结束时间
        orderName: "",
        orderType: "",
        id: "",
        progress:'',
        belongToName: "",
        belongToId: Cookies.get("userId"),
        communicationType:''
      },
      trackingPeople: Cookies.get("realName"),
      loading: false, // 加载标识
      // 限制跟进时间
      pickerOptions: { 
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;//如果没有后面的-8.64e7就是不可以选择今天的 
        }
      },
      pageRequest2: {
        pageNum: 1,
        pageSize: 10
      },
    };
  },
  methods: {
    // 客户类型
    get_student_type() {
      this.student_type_options=JSON.parse(localStorage.getItem('schoolType'))
    },

    // 客户来源
    get_student_data_from() {
      this.student_data_from_options=JSON.parse(localStorage.getItem('schoolSource'))
    },
    get_dataTime() {
      let dateTime = new Date();
      this.saveData.trackingDate = this.dateFormat(dateTime);
      let mytime=dateTime.toLocaleTimeString('chinese', { hour12: false });       //获取当前时间
      this.mytime=mytime
    },
    // 获取方式
    get_student_data_from_type() {
      this.student_data_from_type_options=JSON.parse(localStorage.getItem('schoolDataFromType'))
    },

    // 客户进展
    get_student_progress() {
      this.student_progress_options=JSON.parse(localStorage.getItem('schoolProgress'))
    },

    student_progress_change(value) {
      this.queryBox.student_progressValue = value.toString();
    },

    // 学段
    get_level_cache() {
      this.student_level_cache_options=JSON.parse(localStorage.getItem('schoolSection'))
    },

    // 获取分页数据
    findPage: function(data) {
      if (data !== null) {
        this.loading=true
        this.pageRequest = data.pageRequest;
      }

      //如果创建时间查询的时候选择了，给查询参数赋值
      if (this.createDateArr.length > 0) {
        this.queryBox.createDateStart = this.createDateArr[0];
        this.queryBox.createDateEnd = this.createDateArr[1];
      }

      //如果跟进时间查询的时候选择了，给查询参数赋值
      if (this.trackingDateArr.length > 0) {
        this.queryBox.trackingDateStart = this.trackingDateArr[0];
        this.queryBox.trackingDateEnd = this.trackingDateArr[1];
      }
      this.queryBox.queryInterface = 4;
      this.queryBox.pageNum = this.pageRequest.pageNum;
      this.queryBox.pageSize = this.pageRequest.pageSize;
      if (this.schoolSectionArr.length > 0) {
        this.queryBox.schoolSection = this.schoolSectionArr.join(",");
      }else if (this.schoolSectionArr.length==0){
        this.queryBox.schoolSection =''
      }
      this.$api.school
        .myCustomerQueryList(this.queryBox)
        .then(res => {
          let content = { content: res.listSchoolInfo, totalSize: res.total };
          this.pageResult = content;
          this.pageResult.content.forEach(item => {
            //转换地区
            if (
              (item.province == null && item.city == null) ||
              (item.province == "null" && item.city == "null")
            ) {
              item.diqu = "";
            } else {
              item.diqu = CodeToText[item.province] + CodeToText[item.city]+ CodeToText[item.area];
            }
            //转换来源
            this.student_data_from_options.forEach(type_item => {
              if (type_item.key == item.dataFrom) {
                item.laiyuan = type_item.value;
              }
            });
            //转换客户类型
            this.student_type_options.forEach(type_item => {
              if (type_item.key == item.type) {
                item.leixing = type_item.value;
              }
            });

            //转换客户进展
            this.student_progress_options.forEach(type_item => {
              if (type_item.key == item.progress) {
                item.jinzhan = type_item.value;
              }
            });

            // 转换学段
            if (item.schoolSection != "" && item.schoolSection != null) {
              let schoolSection = item.schoolSection.split(",");
              let sectionStr = "";
              schoolSection.forEach((schoolSection, index) => {
                this.student_level_cache_options.forEach(level_cache => {
                  if (level_cache.key == schoolSection) {
                    sectionStr = sectionStr + level_cache.value + ",";
                  }
                });
              });
              item.xueDuan = sectionStr.substring(
                0,
                sectionStr.lastIndexOf(",")
              );
            }
          });
          this.loading=false
        })
        .then(data != null ? data.callback : "");
    },

    // 查询学生跟进列表
    findPage2(data){
      if (data !== null) {
          this.pageRequest2 = data.pageRequest;
      }
      this.$api.school.schooldetail({id:this.saveData.schoolId ,pageSize:this.pageRequest2.pageSize,pageNum: this.pageRequest2.pageNum}).then(res=>{     
          let content = {'content':res.trackLists,'totalSize':res.total};
          this.stuqueryTrackingData=content;
          this.stuqueryTrackingData.content.forEach(item=>{
              this.student_type_options.forEach(type_item=>{
                if(type_item.key==item.typeTrack){
                    item.typeTrack=type_item.value
                }
              })

              this.student_progress_options.forEach(progress_item=>{
                  if(progress_item.key==item.progressTrack){
                      item.progressTrack=progress_item.value
                  }
              })
                
                 
              this.student_type_options.forEach(type_item=>{
                  if(type_item.key==item.customerType){
                      item.customerType=type_item.value
                  }
              })
             
             this.student_communication_type.forEach(communication_item=>{
                  if(communication_item.key==item.communicationType){
                      item.communicationType=communication_item.value
                  }
              })
              
              
          })    
      }).then(data != null ? data.callback : "");
    },
    // 搜索
    get_subcentersearch() {
      this.loading=true
      this.queryBox.province = this.selectedOptions[0];
      this.queryBox.city = this.selectedOptions[1];
      this.queryBox.area = this.selectedOptions[2];
      this.pageRequest.pageNum = 1;
      this.findPage(null);
    },

    // 重置
    reset(queryBox) {
      this.findPage(null);
      this.$refs.queryBox.resetFields();
      this.queryBox.type = "";
      this.queryBox.dataFrom = "";
      this.queryBox.progress = "";
      this.queryBox.providerAgent = "";
      this.queryBox.createDate = "";
      this.trackingDateArr = "";
      this.createDateArr = "";
      this.queryBox.createDateStart = "";
      this.queryBox.createDateEnd = "";
      this.queryBox.trackingDateStart = "";
      this.queryBox.trackingDateEnd = "";
      this.selectedOptions = [];
      this.queryBox.schoolSection=[]
      this.schoolSectionArr = [];
      this.pageRequest.pageNum = 1;
    },
    // 批量分配
    handlebatchdistribution(params) {
      this.batchdistribution = true;
      this.ids = [];
      let idstu = this.selections.map(item => item.id);
      this.ids = idstu;
    },

    // 批量分配提交
    batchdistributionsubmit() {
      this.AllotData.schoolIds = this.ids;
      this.$api.school.schoolAssign(this.AllotData).then(res => {
        if (res.result === 1) {
          this.$message({ message: res.msg, type: "success" });
          this.batchdistribution = false;
          this.findPage(null);
        } else {
          this.$message({ message: res.msg, type: "error" });
        }
      });
    },

    // 批量删除
    handleBatchDelete() {
      let schids = this.selections.map(item => item.id);
      this.$confirm(
        "确认删除" + this.selections.length + "个客户吗？",
        "提示",
        {}
      ).then(() => {
        this.editLoading = true;
        this.$api.school
          .schoolDelete({
            schoolIds: this.ids,
            dateType: 4
          })
          .then(res => {
            if (res.result == 1) {
              this.$message({ message: "删除成功", type: "success" });
              this.findPage(null);
            } else {
              this.$message({ message: "删除失败", type: "errory" });
            }
          });
      });
    },

    // 解锁锁定
    changeSwitch: function(data) {
      this.$api.school
        .schoolInfoLock({
          schoolId: data.row.id,
          isLock: data.row.isLock
        })
        .then(res => {
          if (res.result == 1) {
            this.$message({ message: res.msg, type: "success" });

            //执行查询接口，刷新列表信息
            this.queryBox.queryInterface = 4;
            this.queryBox.pageNum = this.pageRequest.pageNum;
            this.queryBox.pageSize = this.pageRequest.pageSize;
            this.$api.school
              .cusomerschoolList(this.queryBox)
              .then(res => {
                this.pageResult.content = res.listSchoolInfo;
              })
              .then(data != null ? data.callback : "");
          } else {
            this.$message({ message: res.msg, type: "error" });
          }
        });
    },

    // 批量导入
    customerManagerImport: function() {
      this.uploadOem = true;
      if(this.form.file!=''){
        this.$refs.uploadExcel.clearFiles()
        this.form.file=''
      } 
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: "警告",
        message: `只能选择 ${
          this.limitNum
        } 个文件，当前共选择了 ${files.length + fileList.length} 个`
      });
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      this.form.file = file.raw;
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      let size = file.size / 1024 / 1024;
      if ((extension !== "xlsx") & "xls") {
        this.$notify.warning({
          title: "警告",
          message: `只能上传Excel97-2004（即后缀是.xls）的文件`
        });
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      this.$refs.uploadExcel.clearFiles();
      this.form.file=''
      this.$notify.success({
        title: "成功",
       message: `文件上传成功,数据处理中,稍后在我的消息中查看！`
      });
    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      this.$notify.error({
        title: "错误",
        message: `文件上传失败`
      });
    },
    uploadFile() {
      let formData = new FormData();
      formData.append("file", this.form.file);
      axios
        .post(this.uploadUrl, formData, {
          "Content-Type": "multipart/form-data"
        })
        .then(res => {
          if (res.data.result == 1) {
            let path = res.data.fileUrl;
            this.$api.school.myCustomerImport({ path: path }).then(res => {
               if(res.result==2){
                this.$message({
                  message: res.msg,
                  type: "error"
                });
                this.handleError();
              }else{
                this.$message({
                  message: res.msg,
                  type: "success"
                });
                this.handleSuccess();
              }
              this.uploadOem = false;
              this.findPage(null);
            });
          } else {
            this.handleError();
          }
        });
    },

    // 删除上传列表操作
    handleRemove(file, fileList) {
      this.form.file=''
    },

    // 下载模板
    downloadTmpl() {
     this.getSchoolTempl()
    },

    // 获取部门数据
    get_dept_data() {
      this.$api.dropdown.deptLevel3().then(res => {
        this.deptData = res.departmentInfoList;
      });
    },

    //划分方式 控制部门人员显示
    deptmodeoptionsChange(value) {
      if (value == 9) {
        this.isShowFlag = 2;
        this.AllotData.belong_to_type = 1; //个人
        this.AllotData.thirdLevelDepartment = 0; //清空
      } else if (value == 11) {
        this.isShowFlag = 1;
        this.AllotData.belong_to_type = 2; //部门
        this.AllotData.belongToId = 0;
      } else {
        this.isShowFlag = 0;
      }
    },

    // 点击部门
    handleTreeSelectChange3Add(data, node) {
      this.deptinputValue = data.deptName;
      this.AllotData.thirdLevelDepartment = data.id;
      this.AllotData.belongToId = data.id;
      this.AllotData.belongToId=''
      this.get_dept_user();
    },

    // 获取部门用户
    get_dept_user() {
      this.$api.student
        .queryUserList({ get_dept_user: this.AllotData.thirdLevelDepartment })
        .then(res => {
          this.deptuseroption = res.userInfoList;
        });
    },

    // 查看客户档案
    handleSee: function(params) {
      this.dataForm = Object.assign({}, params.row);
      this.$router.push({
        path: "/Customerfile/School",
        query: {
          id: this.dataForm.id
        }
      });
    },

    // 修改客户档案
    handleEdit: function(params) {
      this.dataForm = Object.assign({}, params.row);
      this.$router.push({
        path: "/Customerfile/EditSchool",
        query: {
          id: this.dataForm.id
        }
      });
    },

    // 获取选中的表格数据
    selectionChange: function(params) {
      let selectionsLength = params.selections.length;
      this.selections = params.selections;

      this.ids = [];
      let idstu = this.selections.map(item => item.id);
      this.ids = idstu;
    },

    // 新增客户
    handleNewADD: function() {
      this.$router.push({
        path: "/Customerfile/AddSchool",
        query: {
          createType: "4"
        }
      });
    },
    // 查看客户档案
    handleSee: function(params) {
      this.dataForm = Object.assign({}, params.row);
      this.$router.push({
        path: "/Customerfile/School",
        query: {
          id: this.dataForm.id
        }
      });
    },
    // 客户跟进
    handleFollow: function(params) {
      this.pageRequest2.pageNum='1'
      this.agentName = params.row.agentName;
      this.addFollow = true;
      this.saveData.schoolId = params.row.id;
      this.saveData.trackingNum = params.row.trackingNum;
      this.saveData.name = params.row.name;
      this.saveData.contactTrack=params.row.name;
      this.saveData.communicationType='1';
      this.saveData.type=params.row.type;
      this.saveData.progress=params.row.progress;
      this.findPage2(null)
    },
    // 提交跟进数据
    handleSave() {
      this.$api.school.saveTrack(this.saveData).then(res => {
        if (res.result != 1) {
          this.$message({
            message: res.msg,
            type: "error"
          });
        } else {
          this.$message({
            message: res.msg,
            type: "success"
          });
          this.addFollow = false;
          this.saveData.progress = "";
          this.saveData.type = "";
          this.saveData.nextTrackingDate = "";
          this.saveData.communicationContent = "";
          this.saveData.communicationType = "";
          this.saveData.contactTrack = "";
          this.findPage(null);
        }
      });
    },
    // 获取时间
    dateFormat: function(time) {
      var date = new Date(time);
      var year = date.getFullYear();
      /* 在日期格式中，月份是从0开始的，因此要加0
       * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
       * */
      var month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hours =
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      var minutes =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      var seconds =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // 拼接
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    // 沟通形式
    get_contractType() {
      this.$api.school.school_communication_type().then(res => {
        this.student_communication_type = res.keyValueList;
      });
      this.saveData.belongToName = this.trackingPeople;
    },
  },
  mounted() {
    this.get_student_type();
    this.get_student_data_from();
    this.get_student_data_from_type();
    this.get_student_progress();
    this.get_level_cache();
    this.get_dept_data();
    this.get_dataTime();
    this.get_contractType();
  }
};
</script>
<style >
@import url("../../assets/queryBox.css");
</style>
<style lang='scss'  scope>
.add-btns .el-button:nth-child(1) {
  margin-right: 10px;
}
.second-contain-box {
  width: 95%;
  margin: 0 auto;
  .el-col {
    text-align: left;
    margin: 4px 0;
  }
  .el-row{
    margin: 0 0 !important;
  }
  .el-col i {
    font-style: normal;
    display: inline-block;
    margin-top: 10%;
  }
}

</style>
<style>
.school-pop .el-row .el-col{
  margin-left: 0;
}
</style>


